const validate = require('../middleware/validator')
const {
    body,
    param
} = require('express-validator')
const response = require('../utils/response')
const mongoose = require('mongoose')
const Taskaudit = require('../models/taskaudit')


//审核的校验
exports.adoptAudit = [
    validate([
        body('userId')
        .notEmpty().withMessage('用户id不能为空~~'),
    ]),
    async (req, res, next) => {
        const fileId = req.params.fileId
        const audit = await Taskaudit.findOne({fileId}).lean()
        if (!audit) {
            return response(res, 404, '找不到审核数据', null)
        }
        if (audit.status === 2) return response(res, 402, "该任务已被打回，请勿重复操作~~", null)
        req.audit = audit
        //进度大于0，任务状态：进行中
        // if (req.body.process > 0 && task.status === 0) {
        //     await Task.findByIdAndUpdate(taskId,{status:1})
        // }
        // req.task = task
        next()
    },
]

// 审核列表校验
exports.taskAudit = [
    validate([
        body('userId')
        .notEmpty().withMessage('用户id不能为空~~'),
    ])
]